package great.project.config;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class TimingTask implements Runnable {

    private static final ExecutorService es = new ThreadPoolExecutor(10, 20,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(10),
            new DynamicTaskConsumeThreadFactory());

    private String expression;

    private String taskId;

    private Runnable runnable;

    public String getTaskId() {
        return taskId;
    }

    public TimingTask() {
    }

    public TimingTask(Runnable runnable) {
        this.runnable = runnable;
    }

    public TimingTask(String expression, String taskId, Runnable runnable) {
        this.expression = expression;
        this.taskId = taskId;
        this.runnable = runnable;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }


    @Override
    public void run() {
        System.out.println("我是run ::"+taskId + "::" + expression);
//        es.execute(runnable);
    }

    public String getExpression() {
        return expression;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }

    @Override
    public String toString() {
        return "TimingTask{" +
                "expression='" + expression + '\'' +
                ", taskId='" + taskId + '\'' +
                '}';
    }
}
